package com.anjubao.parking.municipal.parkinglot.dto;

import com.anjubao.parking.municipal.common.exception.ServiceException;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.time.LocalTime;

/**
 * 停车场计费规则详情
 *
 * @author zhuchunfeng
 */
@Getter
@Setter
@TableName("parking_lot_bill_rule_sub")
@ApiModel(value = "ParkingLotBillRuleSub", description = "停车场计费规则详情")
public class BillRuleSubDto {

//    @TableField(value="id")
//    @ApiModelProperty(name="id",value = "主键id")
//    private Long id;
//
//    @TableField(value="code")
//    @ApiModelProperty(name="code",value = "计费详情编码")
//    private String code;

    @TableField(value = "rule_type")
    @ApiModelProperty(name = "ruleType", value = "收费规则类型，0：24小时统一标准收费规则  1：晚间收费规则",required = true)
    @NotNull
    private Integer ruleType;

    @TableField(value = "day_time_section")
    @ApiModelProperty(name = "dayTimeSection", value = "白天时间段，多少分钟为一段，单位为秒,当rule_type=0时，复用此字段",required = true)
    @NotNull
    private Integer dayTimeSection;

    @TableField(value = "day_fee_section")
    @ApiModelProperty(name = "dayFeeSection", value = "白天每一段收多少钱，单位为分，当rule_type=0时，复用此字段",required = true)
    @NotNull
    private Integer dayFeeSection;

    @TableField(value = "night_time_start")
    @ApiModelProperty(name = "nightTimeStart", value = "晚间开始时间：hh:mm:ss rule_type为1时必填")
    @JsonFormat(pattern = "HH:mm:ss")
    private LocalTime nightTimeStart;

    @TableField(value = "night_time_end")
    @ApiModelProperty(name = "nightTimeEnd", value = "晚间结束时间：hh:mm:ss rule_type为1时必填")
    @JsonFormat(pattern = "HH:mm:ss")
    private LocalTime nightTimeEnd;

    @TableField(value = "night_time_section")
    @ApiModelProperty(name = "nightTimeSection", value = "晚间时间段，多少分钟为一段，单位为秒 rule_type为1时必填")
    private Integer nightTimeSection;

    @TableField(value = "night_fee_section")
    @ApiModelProperty(name = "nightFeeSection", value = "晚间每一段收多少钱，单位为分 rule_type为1时必填")
    private Integer nightFeeSection;

    @TableField(value = "note")
    @ApiModelProperty(name = "note", value = "备注")
    private String note;

    public void validate() {
        if (ruleType == 1) {
            if (nightTimeStart == null ||
                    nightTimeEnd == null ||
                    nightTimeSection == null ||
                    nightFeeSection == null) {
                throw new ServiceException("参数有误");
            }

        }
    }


}